const app = getApp()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        status:-1,
        urlList:['ouhang','oumake','linghang','xiangling']
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        let that=this;
        var parent_id=options.parent_id;
        var id=options.id;
        if(id==undefined){

        }else{
            this.getIndex(id);
        }
        if(parent_id!=undefined){
            this.setData({
                parent_id:parent_id
              })
              wx.setStorageSync('parent_id',parent_id);
        }else{
            parent_id = wx.getStorageSync('parent_id');
        
        }
        var open=wx.getStorageSync('open');
        if(open==""){
            wx.navigateTo({
              url: '../login/index?parent_id='+parent_id,
            })
        }
        wx.showShareMenu({
            menus: ['shareAppMessage', 'shareTimeline'],
            success(res) {
              console.log(res)
            },
            fail(e) {
              console.log(e)
            }
          })             
        that.setData({
            platform:app.globalData.platform,    
            open:open,
            width:app.globalData.windowWidth,
            height:app.globalData.windowHeight,
            statusBarHeight:app.globalData.statusBarHeight,
            navHeight:app.globalData.navHeight,
            marginTop:app.globalData.navTitleTop,
            domain:app.globalData.platUrl,
            uploadUrl:app.globalData.uploadUrl,
          })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
      
    },
    getIndex:function(id){
        let that = this;
        var open=wx.getStorageSync('open');       
        wx.request({
          url: app.globalData.platUrl+'prize/getIndex',
          data:{from:1,user_id:open.user_id,id:id},
          success:res=>{
              console.log(res);
            var data=res.data;
            that.setData({
            list:data.list,
             shareTitle:data.shareTitle,
             shareLogo:data.shareLogo,
             shareIndex:data.shareIndex,
             backgroud:data.backgroud

            })
          }
      })
    },
     getList:function(e){
        console.log(e);
        let data=this.data;
        var status = e.currentTarget.dataset.status;
        wx.navigateTo({
          url:data.urlList[status],
        })

        },
    goBack:function(){
        wx.navigateBack();
      },
      goIndex:function(){
        wx.reLaunch({
          url: '../index/index',
        })
      },
      goto:function(e){
        console.log(e);
        var url=e.currentTarget.dataset.url;
        var index=e.currentTarget.dataset.index;
        var parent_id=wx.getStorageSync('parent_id');
        if(url=="#"){

        }else if(url=='phone'){
            wx.makePhoneCall({
              phoneNumber: '400-800-2177',
            })
        }else if(url=='coupon'){
            this.getCoupon();
        }else{
            if(index==1){
                wx.reLaunch({               
                    url: url,
                  })
            }else{
                wx.navigateTo({
                    url: url,
                  })
            }
           
        }
        console.log(url);
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareTimeline(){
        //console.log(e);
        var title=this.data.shareTitle;
        var shareLogo=this.data.shareLogo;
        var open=wx.getStorageSync('open');

        var parent_id=open.user_id;
         this.setData({
           share:true
         });
         console.log(shareLogo);
         console.log(title);
         return{
           title: title,                 
           query: 'parent_id='+parent_id,        
           imageUrl:shareLogo      
           }
       },
       onShareAppMessage(e) {
        var open=wx.getStorageSync('open');
        var parent_id=open.user_id;
        var that = this;
        var title=this.data.shareTitle;
        var shareLogo=this.data.shareIndex;
   　　var shareObj = {
   　　　　title: title,    
   　　　　path: '/pages/index/index?parent_id='+parent_id,   
   　　　　imageUrl: shareLogo 
   　　　
   　　}
   　　// 来自页面内的按钮的转发
   　　if( e.from == 'button' ){
     　　　shareObj.title=title;
   　　　　shareObj.path = '/pages/index/index?parent_id='+parent_id;
   　　}
   console.log(shareObj);
   　　// 返回shareObj
   　　return shareObj;
    }
})